package sim.app.panicspreading;

import ec.util.MersenneTwisterFast;
import sim.engine.Schedule;
import sim.engine.SimState;
import sim.field.grid.IntGrid2D;
import sim.field.grid.SparseGrid2D;

public class PanicSpreading extends SimState {
	
	private static final long serialVersionUID = -3506386867151262065L;
	
	public static final int GRID_HEIGHT = 100;
    public static final int GRID_WIDTH = 100;
    
    public int numAgents = 500;
    
    public static final int EVENT = 1;
    
    public SparseGrid2D agentGrid;
    public IntGrid2D eventGrid;
    
    private MersenneTwisterFast r;
    
    public PanicSpreading(long seed) {
		super(seed);	
	}
    
    public void start() {
        agentGrid = new SparseGrid2D(GRID_WIDTH, GRID_HEIGHT);
        eventGrid= new IntGrid2D(GRID_WIDTH, GRID_HEIGHT, 0);
        
        r = new MersenneTwisterFast();
        
        eventGrid.field[r.nextInt(GRID_WIDTH)][r.nextInt(GRID_HEIGHT)] = EVENT;
        
        for(int i = 0; i < numAgents; i++) {
        	Victim a = new Victim();
        	agentGrid.setObjectLocation(a, r.nextInt(GRID_WIDTH), r.nextInt(GRID_HEIGHT));
        	schedule.scheduleRepeating(Schedule.EPOCH + i, 0, a, 1);
        }
    }
    
    public static void main(String[] args)
    {
    	doLoop(PanicSpreading.class, args);
    	System.exit(0);
    }    
}

